const tencentcloud = require("tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js")


exports.main = async (event, context) => {
    const client = newWedaClient(process.env.SecretId, process.env.SecretKey);
    const envId = context.namespace
    return await webHookUrl(client, envId)
}

async function webHookUrl(client, envId) {
    const hook = {
        "FlowId": "1752156960273129474",
        "WebhookId": "trigger_s3px2nkkz",
        "EnvId": envId
    }
    const result = await client.doRequest("DescribeAutomationWebhookUrl", hook)
    console.log("查询工作流触点WebHook----->", hook, result)
    return result;
}


function newWedaClient(secretId, secretKey) {
    const client = new tencentcloud.AbstractClient(
        "lowcode.tencentcloudapi.com",
        "2021-01-08", {
            // 腾讯云认证信息
            credential: {
                secretId: secretId,
                secretKey: secretKey,
            },
            // 产品地域
            region: "ap-shanghai",
            // 可选配置实例
            profile: {
                signMethod: "HmacSHA1", // 签名方法
                httpProfile: {
                    reqMethod: "POST", // 请求方法
                    reqTimeout: 30, // 请求超时时间，默认60s
                },
            },
        }
    )
    return client
}